package com.springcloud.client.core.filter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import feign.Logger;
import feign.RequestInterceptor;
import feign.RequestTemplate;

/**
 * Feign请求拦截器
 * @author Administrator
 *
 */
@Configuration
public class FeignBasicAuthRequestInterceptor implements RequestInterceptor{
	
	@Override
	public void apply(RequestTemplate template) { 
		template.header("Authorization", System.getProperty("fangjia.auth.token"));
	}
	
	/**
     * 日志级别
     * @return
     */
    @Bean  
    Logger.Level feignLoggerLevel() {  
        return Logger.Level.FULL;  
    }

    /**
     * 创建Feign请求拦截器，在发送请求前设置认证的token,各个微服务将token设置到环境变量中来达到通用
     * @return
     */
    @Bean
    public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new FeignBasicAuthRequestInterceptor();
    }

	

}
